package com.mtl.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.mtl.common.tool.api.R;
import com.mtl.common.tool.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mtl.user.domain.User;
import com.mtl.user.service.IUserService;
import java.util.List;
import java.util.Arrays;

/**
 * 用户管理 控制器
 *
 * @author qms
 * @since 2019-08-06
 */
@RestController
@RequestMapping("/admin/user")
@Api(value = "用户管理", tags = "用户管理接口")
public class UserController {
    @Autowired
	private IUserService userService;

	/**
	* 详情
	*/
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入user", position = 1)
	public R<User> detail(Integer id) {
		User detail = userService.findById(id);
		return R.data(detail);
	}

	/**
	* 分页 用户管理
	*/
	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入user", position = 2)
	public R<Page<User>> page(Integer page,Integer size,String search) {
		Page<User> pages = userService.findPage(page,size,search);
		return R.data(pages);
	}
	/**
	 * 名字查找 用户管理
	 */
	@GetMapping("/name")
	@ApiOperation(value = "名字查找", notes = "传入user", position = 2)
	public R<Page<User>> name(String search) {
		Page<User> pages = userService.findName(search);
		return R.data(pages);
	}
	/**
	* 新增或修改 用户管理
	*/
	@PostMapping("/submit")
	@ApiOperation(value = "新增或修改", notes = "传入user", position = 6)
	public R submit(@RequestBody User user) {
		return R.status(userService.saveOrUpdate(user));
	}

	/**
	* 删除 用户管理
	*/
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestBody Integer[] ids) {
		return R.status(userService.deleteBatch(Arrays.asList(ids)));
	}

}
